if(typeof oObject!="object")window.oObject={};var Errors={result_unval:"Error in result",result_empty:"Empty result"};function JsTc(oHandler,arSites,sParser,arParams){var t=this;var tmp=0;t.oObj=typeof oHandler=="object"?oHandler:document.getElementById("TAGS");t.arSites=arSites;t.arParams=BX.type.isPlainObject(arParams)?arParams:{};t.selfFolderUrl=t.arParams.selfFolderUrl||"/bitrix/admin/";if(sParser){t.sExp=new RegExp("["+sParser+"]+","i")}else{t.sExp=new RegExp(",")}t.oLast={str:false,arr:false};t.oThis={str:false,arr:false};t.oEl={start:false,end:false};t.oUnfinedWords={};t.bReady=true;t.eFocus=true;t.aDiv=null;t.oDiv=null;t.oActive=null;t.oPointer=Array();t.oPointer_default=Array();t.oPointer_this="input_field";t.oObj.onblur=function(){t.eFocus=false};t.oObj.onfocus=function(){if(!t.eFocus){t.eFocus=true;setTimeout(function(){t.CheckModif("focus")},500)}};t.CHttpRequest=new JCHttpRequest;t.oLast["arr"]=t.oObj.value.split(t.sExp);t.oLast["str"]=t.oLast["arr"].join(":");setTimeout(function(){t.CheckModif("this")},500);this.CheckModif=function(e){var r=false,o=0,i=false,n="",a={};if(!t.eFocus)return;if(t.bReady&&t.oObj.value.length>0){t.oThis["arr"]=t.oObj.value.split(t.sExp);t.oThis["str"]=t.oThis["arr"].join(":");if(t.oThis["str"]&&t.oThis["str"]!=t.oLast["str"]){a["position"]=TCJsUtils.getCursorPosition(t.oObj);if(a["position"]["end"]>0&&!t.sExp.test(t.oObj.value.substr(a["position"]["end"]-1,1))){a["arr"]=t.oObj.value.substr(0,a["position"]["end"]).split(t.sExp);r=t.oThis["arr"][a["arr"].length-1];t.oEl["start"]=a["position"]["end"]-a["arr"][a["arr"].length-1].length;t.oEl["end"]=t.oEl["start"]+r.length;t.oEl["content"]=r;t.oLast["arr"]=t.oThis["arr"];t.oLast["str"]=t.oThis["str"]}}if(r){for(o=2;o<=r.length;o++){n=r.substr(0,o);if(t.oUnfinedWords[n]=="!fined"){i=true;break}}if(!i)t.Send(r)}}setTimeout(function(){t.CheckModif("this")},500)};t.Send=function(sSearch){if(!sSearch)return false;var oError={};t.CHttpRequest.Action=function(data){var result={};t.bReady=true;try{eval("result = "+data+";")}catch(t){oError["result_unval"]=t}if(TCJsUtils.empty(result))oError["result_empty"]=Errors["result_empty"];try{if(TCJsUtils.empty(oError)&&typeof result=="object"){if(!(result.length==1&&result[0]["NAME"]==t.oEl["content"])){t.Show(result);return}}else{t.oUnfinedWords[t.oEl["content"]]="!fined"}}catch(t){oError["unknown_error"]=t}return};var queryString=t.selfFolderUrl+"search_tags.php?search="+encodeURIComponent(sSearch);try{if(t.arSites&&t.arSites.constructor.toString().indexOf("Array")!=-1){for(var i=0,length=t.arSites.length;i<length;i++)queryString+="&site_id[]="+encodeURIComponent(t.arSites[i])}var ck_box=document.getElementById("ck_"+oHandler.id);if(ck_box){if(ck_box.checked)queryString+="&order_by=NAME"}}catch(t){}t.CHttpRequest.Send(queryString)};t.Show=function(e){t.Destroy();var r=BX.pos(t.oObj);t.oDiv=document.body.appendChild(document.createElement("DIV"));t.oDiv.id=t.oObj.id+"_div";t.oDiv.className="bx-popup-menu";t.oDiv.style.position="absolute";t.aDiv=t.Print(e,["NAME","CNT"]);if(t.oDiv.offsetWidth<300)t.oDiv.style.width=t.oDiv.offsetWidth+"px";else t.oDiv.style.width="300px";t.oDiv.style.zIndex=5e3;jsFloatDiv.Show(t.oDiv,r["left"],r["bottom"]);BX.bind(document,"click",t.CheckMouse);BX.bind(document,"keydown",t.CheckKeyword)};t.Print=function(e,r){var o=null;var i="";var n="";var a=Array();var s=Array();var l=0;var u=0;i=t.oDiv.id;var c='<table cellspacing="0" cellpadding="0" border="0"><tr><td class="popupmenu">'+'<table cellspacing="0" cellpadding="0" border="0" width="100%">';for(var d=0,p=e.length;d<p;d++){o=e[d];s=Array();s["ID"]=o["ID"]&&o["ID"].length>0?o["ID"]:l++;s["GID"]=i+"_"+s["ID"];s["NAME"]=TCJsUtils.htmlspecialcharsEx(o["NAME"]);s["CNT"]=o["CNT"];a[s["GID"]]=s;t.oPointer.push(s["GID"]);c+="<tr><td>"+'<table cellspacing="0" cellpadding="0" border="0" class="popupitem" '+'onmouseout="window.oObject.'+t.oObj.id+".Init(); this.className='popupitem';\" "+'onmouseover="window.oObject.'+t.oObj.id+".Init(); this.className='popupitem popupitemover'\" "+'onclick="window.oObject.'+t.oObj.id+'.oActive=this.id;" '+'id="'+s["GID"]+'" name="'+i+'_table">'+'<tr><td class="gutter"><div></div></td>'+'<td class="item" id="'+s["GID"]+'_NAME" width="90%">'+s["NAME"]+"</td>"+'<td class="item" id="'+s["GID"]+'_CNT" width="10%" align="right">'+s["CNT"]+"</td>"+"</tr></table></td></tr>"}c+="</table></td></tr></table>";t.oPointer.push("input_field");t.oPointer_default=t.oPointer;t.oDiv.innerHTML=c;return a};t.Destroy=function(){try{jsFloatDiv.Close(t.oDiv);t.oDiv.parentNode.removeChild(t.oDiv)}catch(t){}t.oPointer=Array();t.oPointer_default=Array();t.oPointer_this="input_field";t.oDiv=null;t.aDiv=null;t.oActive=null;BX.unbind(document,"click",t.CheckMouse);BX.unbind(document,"keydown",t.CheckKeyword)};t.Replace=function(){if(typeof t.oActive=="string"){var e=t.aDiv[t.oActive];var r="";if(typeof e=="object"){var o=document.createElement("span");o.innerHTML=e["NAME"].replace(/&quot;/g,'"').replace(/&amp;/g,"&");r=o.innerHTML}var i=t.oEl["start"];while(i<t.oObj.value.length&&t.oObj.value.substring(i,i+1)==" ")i++;t.oObj.value=t.oObj.value.substring(0,i)+r.replace(/&lt;/g,"<").replace(/&gt;/g,">")+t.oObj.value.substr(t.oEl["end"]);TCJsUtils.setCursorPosition(t.oObj,i+r.length)}return};t.Init=function(){t.oActive=false;t.oPointer=t.oPointer_default;t.Clear();t.oPointer_this="input_pointer"};t.Clear=function(){var e={},r="";e=t.oDiv.getElementsByTagName("table");if(e.length>0&&typeof e=="object"){for(r in e){if(e.hasOwnProperty(r)){var o=e[r];if(o.name==t.oDiv.id+"_table"||t.aDiv[o.id]){o.className="popupitem"}}}}return};t.CheckMouse=function(){t.Replace();t.Destroy()};t.CheckKeyword=function(e){if(!e)e=window.event;var r=null,o=null,i=null;if(37<e.keyCode&&e.keyCode<41||e.keyCode==13){t.Clear();switch(e.keyCode){case 38:r=t.oPointer.pop();if(t.oPointer_this==r){t.oPointer.unshift(r);r=t.oPointer.pop()}if(r!="input_field"){t.oActive=r;o=document.getElementById(r);if(typeof o=="object"){o.className="popupitem popupitemover"}}t.oPointer.unshift(r);break;case 40:r=t.oPointer.shift();if(t.oPointer_this==r){t.oPointer.push(r);r=t.oPointer.shift()}if(r!="input_field"){t.oActive=r;o=document.getElementById(r);if(typeof o=="object"){o.className="popupitem popupitemover"}}t.oPointer.push(r);break;case 39:t.Replace();t.Destroy();break;case 13:t.Replace();t.Destroy();if(BX.browser.IsIE()){e.returnValue=false;e.cancelBubble=true}else{e.preventDefault();e.stopPropagation()}break}t.oPointer_this=r}else{t.Destroy()}return true}}var TCJsUtils={getCursorPosition:function(t){var e={start:0,end:0};if(!t||typeof t!="object")return e;try{if(document.selection!=null&&t.selectionStart==null){t.focus();var r=document.selection.createRange();var o=r.parentElement();var i=r.getBookmark();var n=t.value;var a=t.value;var s="__"+Math.random()+"__";while(n.indexOf(s)!=-1){s="__"+Math.random()+"__"}if(!o||o===null||o.type!="textarea"&&o.type!="text"){return e}r.text=s+r.text+s;n=t.value;e["start"]=n.indexOf(s);n=n.replace(s,"");e["end"]=n.indexOf(s);t.value=a;r.moveToBookmark(i);r.select();return e}else{return{start:t.selectionStart,end:t.selectionEnd}}}catch(t){}return e},setCursorPosition:function(t,e){var r=false;if(typeof t!="object")return false;t.focus();try{if(document.selection!==null&&t.selectionStart===null){var o=document.selection.createRange();o.select()}else{t.selectionStart=e;t.selectionEnd=e}return true}catch(t){return false}},empty:function(t){var e=true;if(t){for(var r in t){if(t.hasOwnProperty(r)){e=false;break}}}return e},htmlspecialcharsEx:function(t){var e=t.replace(/&amp;/g,"&amp;amp;").replace(/&lt;/g,"&amp;lt;").replace(/&gt;/g,"&amp;gt;").replace(/&quot;/g,"&amp;quot;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;");return e},htmlspecialcharsback:function(t){var e=t.replace(/&lt;/g,"<").replace(/&gt;/g,">").replace(/&quot;/g,'"').replace(/&amp;/g,"&");return e}};